home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / CLIPTEXT.PAK / ABOUT.C next >
C/C++ Source or Header  |  1997-05-06  |  8KB  |  286 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993 - 1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   about.c
  9. //
  10. //  PURPOSE:   Displays the "About" dialog box
  11. //
  12. //  FUNCTIONS:
  13. //    CmdAbout        - Displays the "About" dialog box
  14. //    About           - Processes messages for "About" dialog box.
  15. //    MsgAboutInit    - To initialize the about box with version info
  16. //                      from resources.
  17. //    MsgAboutCommand - Process WM_COMMAND message sent to the about box.
  18. //    CmdAboutDone    - Free the about box and related data.
  19. //
  20. //  COMMENTS:
  21. //
  22. //
  23.  
  24. #include <windows.h>            // required for all Windows applications
  25. #include <windowsx.h>
  26.  
  27. #ifdef WIN16
  28. #include "win16ext.h"           // required only for win16 applications
  29. #endif
  30. #include "globals.h"            // prototypes specific to this application
  31. #include "resource.h"
  32.  
  33.  
  34. #ifdef WIN16
  35. // Dialog box procedures must be exported in 16-bit applications for Windows.
  36. LRESULT CALLBACK __export About(HWND, UINT, WPARAM, LPARAM);
  37. #else
  38. LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
  39. #endif
  40.  
  41. LRESULT MsgAboutInit(HWND, UINT, WPARAM, LPARAM);
  42. LRESULT MsgAboutCommand(HWND, UINT, WPARAM, LPARAM);
  43. LRESULT CmdAboutDone(HWND, WORD, WORD, HWND);
  44.  
  45. // About dialog message table definition.
  46. MSD rgmsdAbout[] =
  47. {
  48.     {WM_COMMAND,    MsgAboutCommand},
  49.     {WM_INITDIALOG, MsgAboutInit}
  50. };
  51.  
  52. MSDI msdiAbout =
  53. {
  54.     sizeof(rgmsdAbout) / sizeof(MSD),
  55.     rgmsdAbout,
  56.     edwpNone
  57. };
  58.  
  59. // About dialog command table definition.
  60. CMD rgcmdAbout[] =
  61. {
  62.     {IDOK,     CmdAboutDone},
  63.     {IDCANCEL, CmdAboutDone}
  64. };
  65.  
  66. CMDI cmdiAbout =
  67. {
  68.     sizeof(rgcmdAbout) / sizeof(CMD),
  69.     rgcmdAbout,
  70.     edwpNone
  71. };
  72.  
  73. // Module specific "globals"  Used when a variable needs to be
  74. // accessed in more than on handler function.
  75.  
  76. HFONT hFontCopyright;
  77.  
  78. //
  79. //  FUNCTION: CmdAbout(HWND, WORD, WORD, HWND)
  80. //
  81. //  PURPOSE: Displays the "About" dialog box
  82. //
  83. //  PARAMETERS:
  84. //    hwnd      - Window handle
  85. //    wCommand  - IDM_ABOUT (unused)
  86. //    wNotify   - Notification number (unused)
  87. //    hwndCtrl  - NULL (unused)
  88. //
  89. //  RETURN VALUE:
  90. //
  91. //    Always returns 0 - Message handled
  92. //
  93. //  COMMENTS:
  94. //    To process the IDM_ABOUT message, call DialogBox() to display the
  95. //    about dialog box.
  96.  
  97. #pragma argsused
  98. LRESULT CmdAbout(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  99. {
  100.     DialogBox(hInst, "AboutBox", hwnd, (DLGPROC)About);
  101.     return 0;
  102. }
  103.  
  104.  
  105. //
  106. //  FUNCTION: About(HWND, UINT, WPARAM, LPARAM)
  107. //
  108. //  PURPOSE:  Processes messages for "About" dialog box.
  109. //
  110. //  PARAMETERS:
  111. //    hdlg - window handle of the dialog box
  112. //    wMessage - type of message
  113. //    wparam - message-specific information
  114. //    lparam - message-specific information
  115. //
  116. //  RETURN VALUE:
  117. //    TRUE - message handled
  118. //    FALSE - message not handled
  119. //
  120. //  COMMENTS:
  121. //
  122. //     Display version information from the version section of the
  123. //     application resource.
  124. //
  125. //     Wait for user to click on "Ok" button, then close the dialog box.
  126. //
  127.  
  128. LRESULT CALLBACK About(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  129. {
  130.     return DispMessage(&msdiAbout, hdlg, uMessage, wparam, lparam);
  131. }
  132.  
  133.  
  134. //
  135. //  FUNCTION: MsgAboutInit(HWND, UINT, WPARAM, LPARAM)
  136. //
  137. //  PURPOSE: To initialize the about box with version info from resources.
  138. //
  139. //  PARAMETERS:
  140. //    hwnd - The window handing the message.
  141. //    uMessage - The message number. (unused).
  142. //    wparam - Message specific data (unused).
  143. //    lparam - Message specific data (unused).
  144. //
  145. //  RETURN VALUE:
  146. //    Always returns 0 - message handled.
  147. //
  148. //  COMMENTS:
  149. //    Uses the version apis to retrieve version information for
  150. //    each of the static text boxes in the about box.
  151. //
  152.  
  153. #pragma argsused
  154. LRESULT MsgAboutInit(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
  155. {
  156.     #define POINTSIZE 8
  157.  
  158.     char  szFullPath[256];
  159.     DWORD dwVerHnd;
  160.     DWORD dwVerInfoSize;
  161.     HDC   hDC;
  162.     int   iLogPixelsY, iPointSize;
  163.  
  164.     // Center the dialog over the application window
  165.     CenterWindow(hdlg, GetWindow(hdlg, GW_OWNER));
  166.  
  167.     // Set the copyright font to something smaller than default
  168.     hDC = GetDC(hdlg);
  169.     iLogPixelsY = GetDeviceCaps(hDC, LOGPIXELSY);
  170.     ReleaseDC(hdlg, hDC);
  171.     iPointSize = MulDiv(iLogPixelsY, POINTSIZE, 72);
  172.     iPointSize *= -1;
  173.  
  174.     hFontCopyright = CreateFont(iPointSize,
  175.                                 0, 0, 0,
  176.                                 FW_BOLD,
  177.                                 0, 0, 0, 0,
  178.                                 0, 0, 0, 0,
  179.                                 "Arial");
  180.  
  181.     SendDlgItemMessage(hdlg, 
  182.                        IDD_VERLAST, 
  183.                        WM_SETFONT, 
  184.                        (WPARAM)hFontCopyright,
  185.                        0L);
  186.  
  187.     // Get version information from the application
  188.     GetModuleFileName(hInst, szFullPath, sizeof(szFullPath));
  189.     dwVerInfoSize = GetFileVersionInfoSize(szFullPath, &dwVerHnd);
  190.     if (dwVerInfoSize)
  191.     {
  192.         // If we were able to get the information, process it:
  193.         HANDLE  hMem;
  194.         LPVOID  lpvMem;
  195.         char    szGetName[256];
  196.         int     cchRoot;
  197.         int     i;
  198.  
  199.         hMem = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);
  200.         lpvMem = GlobalLock(hMem);
  201.         GetFileVersionInfo(szFullPath, dwVerHnd, dwVerInfoSize, lpvMem);
  202.         lstrcpy(szGetName, "\\StringFileInfo\\040904E4\\");
  203.         cchRoot = lstrlen(szGetName);
  204.  
  205.         // Walk through the dialog items that we want to replace:
  206.         for (i = IDD_VERFIRST; i <= IDD_VERLAST; i++)
  207.           {
  208.                 BOOL  fRet;
  209.                 UINT  cchVer = 0;
  210.                 LPSTR lszVer = NULL;
  211.                 char  szResult[256];
  212.  
  213.                 GetDlgItemText(hdlg, i, szResult, sizeof(szResult));
  214.                 lstrcpy(&szGetName[cchRoot], szResult);
  215.                 fRet = VerQueryValue(lpvMem, szGetName, (LPVOID) &lszVer, &cchVer);
  216.  
  217.                 if (fRet && cchVer && lszVer)
  218.                 {
  219.                      // Replace dialog item text with version info
  220.                      lstrcpy(szResult, lszVer);
  221.                      SetDlgItemText(hdlg, i, szResult);
  222.                 }
  223.           }
  224.           GlobalUnlock(hMem);
  225.           GlobalFree(hMem);
  226.     }
  227.     return TRUE;
  228. }
  229.  
  230. //
  231. //  FUNCTION: MsgAboutCommand(HWND, UINT, WPARAM, LPARAM)
  232. //
  233. //  PURPOSE: Process WM_COMMAND message sent to the about box.
  234. //
  235. //  PARAMETERS:
  236. //    hwnd - The window handing the message.
  237. //    uMessage - The message number. (unused).
  238. //    wparam - Message specific data (unused).
  239. //    lparam - Message specific data (unused).
  240. //
  241. //  RETURN VALUE:
  242. //    Always returns 0 - message handled.
  243. //
  244. //  COMMENTS:
  245. //    Uses this DipsCommand function defined in wndproc.c combined
  246. //    with the cmdiAbout structure defined in this file to handle
  247. //    the command messages for the about dialog box.
  248. //
  249.  
  250. #pragma argsused
  251. LRESULT MsgAboutCommand(HWND   hwnd,
  252.                         UINT   uMessage, 
  253.                         WPARAM wparam, 
  254.                         LPARAM lparam)
  255. {
  256.     return DispCommand(&cmdiAbout, hwnd, wparam, lparam);
  257. }
  258.  
  259. //
  260. //  FUNCTION: CmdAboutDone(HWND, WORD, HWND)
  261. //
  262. //  PURPOSE: Free the about box and related data.
  263. //
  264. //  PARAMETERS:
  265. //    hwnd - The window handling the command.
  266. //    wCommand - The command to be handled (unused).
  267. //    wNotify   - Notification number (unused)
  268. //    hwndCtrl - NULL (unused).
  269. //
  270. //  RETURN VALUE:
  271. //    Always returns TRUE.
  272. //
  273. //  COMMENTS:
  274. //    Calls EndDialog to finish the dialog session.
  275. //
  276.  
  277. #pragma argsused
  278. LRESULT CmdAboutDone(HWND hdlg, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  279. {
  280.     if (hFontCopyright)
  281.        DeleteObject(hFontCopyright);
  282.  
  283.     EndDialog(hdlg, TRUE);          // Exit the dialog
  284.     return TRUE;
  285. }
  286.